<template>
  <div class="lefttop">
    <div id="main"></div>
  </div>
</template>

<script lang="ts" setup>
import echarts from "echarts";
import { onMounted, reactive } from "vue";
import { getForeinData } from "../../charts";

let option = {
  title: {
    text: "新增确诊TOP10",
    x: "center",
    textStyle: {
      color: "#fff",
    },
  },
  tooltip: {
    trigger: "axis",
    axisPointer: {
      type: "shadow",
    },
  },
  grid: {
    top: "20%",
    left: "3%",
    right: "4%",
    bottom: "3px",
    containLabel: true,
  },
  xAxis: [
    {
      type: "category",
      data: [
        "英国",
        "印度尼西亚",
        "巴西",
        "印度",
        "伊朗",
        "俄罗斯",
        "哥伦比亚",
        "孟加拉国",
        "泰国",
        "马来西亚",
      ],
      axisLine: {
        lineStyle: {
          color: "rgba(255,255,255,0.12)",
        },
      },
      axisLabel: {
        margin: 10,
        color: "#e2e9ff",
        textStyle: {
          fontSize: 8,
        },
      },
    },
  ],
  yAxis: [
    {
      axisLabel: {
        formatter: "{value}",
        color: "#e2e9ff",
      },
      axisLine: {
        show: false,
      },
      splitLine: {
        lineStyle: {
          color: "rgba(255,255,255,0.12)",
        },
      },
    },
  ],
  series: [
    {
      type: "bar",
      data: [
        39538, 38325, 34126, 30093, 25441, 23770, 18206, 11579, 11305, 10972,
      ],
      barWidth: "12px",
      itemStyle: {
        normal: {
          color: new echarts.graphic.LinearGradient(
            0,
            0,
            0,
            1,
            [
              {
                offset: 0,
                color: "rgba(0,244,255,1)", // 0% 处的颜色
              },
              {
                offset: 1,
                color: "rgba(0,77,167,1)", // 100% 处的颜色
              },
            ],
            false
          ),
          barBorderRadius: [30, 30, 30, 30],
          shadowColor: "rgba(0,160,221,1)",
          shadowBlur: 4,
        },
      },
      label: {
        normal: {
          show: false,
          lineHeight: 30,
          width: 80,
          height: 30,
          backgroundColor: "rgba(0,160,221,0.1)",
          borderRadius: 200,
          position: ["-8", "-60"],
          distance: 1,
        },
      },
    },
  ],
};
let list = option.xAxis[0].data;
let lists = option.series[0].data;
onMounted(() => {
  var chartDom = document.getElementById("main");
  var myChart = echarts.init(chartDom);
  getForeinData().then((res) => {
    // console.log(res);
    res.countryAddConfirmRankList.nation = list;
    res.countryAddConfirmRankList.addConfirm = lists;
  });
  myChart.setOption(option);
  window.addEventListener(
    "resize",
    function () {
      myChart.resize();
    },
    false
  );
});
</script>
<style scoped lang="scss">
.lefttop {
  color: #fff;
  width: 510px;
  height: 280px;
  text-align: center;
}
#main {
  height: 335px;
  text-align: center;
  padding: 0 10px;
  margin-top: 10px;
}
</style>
